package com.ifgostudio.framework.web.response;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;

import com.ifgostudio.framework.io.IfgoOutputStream;

public class ResponseWrapper extends HttpServletResponseWrapper {

	private IfgoOutputStream stream;
	private ByteArrayOutputStream byteStream;
	private PrintWriter pw;

	public ResponseWrapper(HttpServletResponse response) {
		super(response);

		this.byteStream = new ByteArrayOutputStream();
		this.stream = new IfgoOutputStream(this.byteStream);
		this.pw = new PrintWriter(this.byteStream);
	}

	@Override
	public ServletOutputStream getOutputStream() throws IOException {
		return stream;
	}

	@Override
	public PrintWriter getWriter() throws IOException {
		return this.pw;
	}

	public String getContent() {
		//过滤空格，必须否则在页面中会有其他字符
		return this.byteStream.toString().trim();
	}

}
